﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace FYPDemo
{
    public partial class addNewPost : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bindDDLCategory();
            }
        }

        protected void btnPost_Click(object sender, EventArgs e)
        {
            int result = 0;
            string Title = "";
            string Creator = Session["username"].ToString();
            int category = 0;
            string content = "";

            Title = txtTitle.Text;
            category = Convert.ToInt32(ddlCategory.SelectedValue);
            content = txtContent.Text;

            result = VirtualCommunication.addNewPost(Title, Creator, category, content);

            if (result > 0)
            {
                MessageBox.Show("Successfully add a new thread");
            }
        }

        protected void bindDDLCategory()
        {
            DataTable dt = VirtualCommunication.listForumCategory();

            ddlCategory.DataSource = dt;
            ddlCategory.DataTextField = "Category";
            ddlCategory.DataValueField = "ID";
            ddlCategory.DataBind();
        }
    }
}